//
//  MyAlertView.m
//  wangzhe
//
//  Created by 李 佳伟 on 2017/12/20.
//  Copyright © 2017年 李 佳伟. All rights reserved.
//

#import "MyAlertView.h"
#import "JTCSM.h"

static CGFloat imagesize = 100;
static CGFloat labelHeight = 40;
static MyAlertView *single = nil;

@implementation MyAlertView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

+(MyAlertView *)shareSingle{
    @synchronized(self){
        if(single == nil){
            
            single =[ [MyAlertView alloc] init];
        }
        
    }
    return single;
}

- (id)init
{
    self= [super init];
    if (self) {
        
        
        imageview = [[UIImageView alloc]initWithFrame:CGRectMake((KSCREENWidth-imagesize)/2, 0, imagesize, imagesize)];
        [self addSubview:imageview];
        
        contentLabel = [UILabel initWithFrame:CGRectMake(0, KVIEW_Y(imageview), KSCREENWidth, labelHeight) text:@"" font:14 textAlignment:NSTextAlignmentCenter texcolor:RGBACOLOR(192, 192, 192, 1) backgroundColor:nil];
        contentLabel.numberOfLines = 2;
        [self addSubview:contentLabel];
        
    }
    return self;
}

- (void)showWithImagename:(NSString *)imagename contentLabel:(NSString *)content superview:(UIView *)superview{
    if ([imagename isEqualToString:@"zhangbenimage.png"]) {
        self.frame = CGRectMake(-20, (superview.frame.size.height-imagesize-labelHeight)/2, KSCREENWidth, imagesize+labelHeight);
    }else{
        self.frame = CGRectMake(0, (superview.frame.size.height-imagesize-labelHeight)/2, KSCREENWidth, imagesize+labelHeight);
    }
    
    imageview.image = [UIImage imageNamed:imagename];
    contentLabel.text = content;
    [superview addSubview:self];
}

- (void)hiddenmyself{
    [self removeFromSuperview];
}

@end
